<template>
  <li class="todo-item" :class="{ completed: task.completed }">
    <input 
      type="checkbox" 
      v-model="task.completed" 
      @change="handleComplete"
    />
    <span>{{ task.text }}</span>
    <button class="delete-btn" @click="handleDelete">删除</button>
  </li>
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue'

const props = defineProps({
  task: {
    type: Object,
    required: true
  }
})
const emits = defineEmits(['toggle-complete', 'delete-task'])

const handleComplete = () => {
  emits('toggle-complete', props.task.id)
}

const handleDelete = () => {
  emits('delete-task', props.task.id)
}
</script>

<style scoped>
.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid #eee;
}
.completed {
  text-decoration: line-through;
  opacity: 0.6;
}
.delete-btn {
  background-color: #f44336;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}
</style>